﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using SheepClock.CustomUIComponents;
using System.Windows.Navigation;
using System.IO.IsolatedStorage;

namespace SheepClock
{
    public partial class Settings : PhoneApplicationPage
    {
        public Settings()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            RunningSheepSwitch.IsON = IsolatedStorageSettings.ApplicationSettings.Contains("SheepRunning") ?
                (bool)IsolatedStorageSettings.ApplicationSettings["SheepRunning"] : true;
            RunningSetting_SetText();

            SheepBaaSwitch.IsON = IsolatedStorageSettings.ApplicationSettings.Contains("SheepBaa") ?
                 (bool)IsolatedStorageSettings.ApplicationSettings["SheepBaa"] : true;
            BaaSetting_SetText();

            base.OnNavigatedTo(e);
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            IsolatedStorageSettings.ApplicationSettings["SheepRunning"] = RunningSheepSwitch.IsON;
            IsolatedStorageSettings.ApplicationSettings["SheepBaa"] = SheepBaaSwitch.IsON;

            IsolatedStorageSettings.ApplicationSettings.Save();

            base.OnNavigatedFrom(e);
        }

        private void RunningSheepSwitch_StateChanged(object sender, Switch.SwitchStateArgs e)
        {
            RunningSetting_SetText();
        }

        private void RunningSetting_SetText()
        {
            if (RunningSheepSwitch.IsON)
                RunningSheepSubtitle.Text = "Run sheep, run!";
            else
                RunningSheepSubtitle.Text = "Not at the moment... :(";
        }

        private void SheepBaaSwitch_StateChanged(object sender, Switch.SwitchStateArgs e)
        {
            BaaSetting_SetText();
        }

        private void BaaSetting_SetText()
        {
            if (SheepBaaSwitch.IsON)
                SheepBaaSubtitle.Text = "Only if you catch it!";
            else
                SheepBaaSubtitle.Text = "No, they don't...";
        }
    }
}